package com.example.backed.task;

import com.example.backed.service.GroupBuyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class GroupBuyTask {

    private final GroupBuyService groupBuyService;

    /**
     * 每分钟检查一次团购活动状态
     */
    @Scheduled(cron = "0 * * * * ?")
    public void checkGroupBuyStatus() {
        try {
            log.info("开始检查团购活动状态");
            groupBuyService.checkAndUpdateGroupBuyStatus();
            log.info("检查团购活动状态完成");
        } catch (Exception e) {
            log.error("检查团购活动状态失败", e);
        }
    }
} 